package main.java;

import org.junit.After;
import org.junit.Test;
import org.junit.runners.Parameterized;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class PatternTest {
    @Test
    public void test_1(){
        String s ="1";


    }
    public static int[] StrToInt(String s){

        return null;
    }
    @Test
    public void test0(){
        Pattern pml = Pattern.compile("\n", Pattern.DOTALL | Pattern.MULTILINE);

        System.out.println(pml.matcher("I dream of engines\nmore engines, all day long").find());

    }
    @Test
    public void test1(){
        String content = "I am noob " +
                "from runoob.com.";

        String pattern = ".*runoob.*";

        boolean isMatch = Pattern.matches(pattern, content);
        System.out.println("字符串中是否包含了 'runoob' 子字符串? " + isMatch);
    }

    @Test
    public void test2() throws Exception {
        String content = "12345678";

        String pattern = "\\{8}";

        boolean isMatch = Pattern.matches(pattern, content);
        System.out.println("字符串中是否包含了 'runoob' 子字符串? " + isMatch);

        System.out.println(content.matches(pattern));
    }
@Test
public void test5() throws Exception {
    // 要验证的字符串
    String str = "这是一个正则表达式字符串查找的\n" +
            "示例12345，正则表达式好厉害呀45678";
    // 正则表达式规则
    String regEx = "\\d+";
    // 编译正则表达式
    Pattern pattern = Pattern.compile(regEx);
    // 忽略大小写的写法
    // Pattern pat = Pattern.compile(regEx, Pattern.CASE_INSENSITIVE);
    Matcher matcher = pattern.matcher(str);

    // 查找字符串中是否有匹配正则表达式的字符/字符串
    while (matcher.find()) {
        System.out.println(matcher.group());
    }
   System.out.println(matcher.groupCount());

}

    @Test
    public void test3() throws Exception {
        String s = "1222 22\n" +
                "2 3\n" +
                "4 5\n" +
                "3";
        Scanner scanner = new Scanner(s);
        Pattern pml = Pattern.compile(" ", Pattern.DOTALL | Pattern.MULTILINE);
        System.out.println(pml.matcher("1222 22\n").groupCount());

        while (!scanner.hasNext(pml)){
            System.out.println(!scanner.hasNext(pml));
            System.out.println(scanner.next());
        }



    }


}
